package buaa.paas.kubectl;

import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.AppsV1Api;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.KubeConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

@Service
public class ApiUtil {
    private ApiClient client;
    private AppsV1Api api;
    private CoreV1Api coreApi;

    public ApiUtil() throws IOException {
        client = ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader("/root/project/kubic/config"))).build();
        io.kubernetes.client.openapi.Configuration.setDefaultApiClient(client);
        api = new AppsV1Api();
        coreApi = new CoreV1Api();
    }

    public AppsV1Api getApi(){
        return api;
    }

    public CoreV1Api getCoreApi(){
        return coreApi;
    }
}
